<?php
namespace app\zjs\controller;
use app\admin\model\Customer;
use app\admin\model\Orders;
use app\common\model\Order;
use app\common\model\Zjslog;
use think\Facade\Session;
use page\Page;
class Personal extends Zjs {
    //put your code here
    protected function _initialize() {
        parent::_initialize();
        if(!session('user_id')){
            $this->redirect(url('publics/bangding'));
        }
    }
     public function index() {
        return $this->fetch('index/personal_info');
    }
    //个人中心
    public function personal_information(){
        $user = Customer::get(session('user_id'));
        $this->assign("userinfo", $user);
        $cash = '统计中';
        $count = Order::where(['tjr_id'=>$user['id'],'status'=>1])->count('id');
        $counts =Order::where(['tjr_id'=>$user['id'],'status'=>1,'ywstate'=>6])->count('id');
        return $this->fetch('index/personal_information',['cash'=>$cash,'count'=>$count,'counts'=>$counts]);
    }
    //查看推荐列表
    public function recommend() {
        $order = new Order();
        $map=[];
        $map['tjr_id']=session('user_id');
        $count      = $order->where($map)->count();// 查询满足要求的总记录数
        $Page       = new Page($count,3);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $Page->setConfig('theme','%UP_PAGE% %HEADER% %DOWN_PAGE%');//定义分页类的的主题
        $show       = $Page->zjsshow();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $data = $order->where($map)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('orderlist', $data);
        $this->assign('page', $show);
        return $this->fetch('index/personal_recommend');
    }
    //查看推荐详情
    public function personal_rec_details() {
        $id = input('id');
        if(empty($id)){
            $this->error('参数丢失');exit;
        }
//        $orderdata = Orders::get($id);
//        $orderdata = Db::name('orders')->where(['order_id'=>$id])->field('id,tel,name,tjtime')->find();
        $orderdata = Orders::where(['order_id'=>$id])->field('id,tel,name,tjtime')->find();
        $log = Zjslog::where(['order_id'=>$orderdata->id])->order('id desc')->select();

//        var_dump($orderdata);
//        echo "<br/>";
//        var_dump($log);

        $this->assign('orderdata', $orderdata);
        $this->assign('loglist', $log);
        return $this->fetch('index/personal_rec_details');
    }
}
